var Main = new function () {
    let M = this,Info = {
        isLogin: false,
        name: "没有登录",
        id:""
    },RunData={
        runCount:0,
        synchronizeCount:0,
        treeData:null,
        isRun:false
    };

    M.getInfo = function () {
        return Info;
    };

    M.setInfo = function (obj) {
        Info.id = obj.id;
        Info.isLogin = true;
        Info.name = obj.name;
    };

    M.getRunData = function () {
        return RunData;
    };

    M.setRunData = function (obj) {
        RunData.runCount = obj.runCount;
        RunData.synchronizeCount = obj.synchronizeCount;
        RunData.treeData = obj.treeData;
        RunData.isRun = true;
    };
    M.growRunCount=function (obj) {
        RunData.runCount++;
        if(RunData.runCount>=RunData.synchronizeCount){
            RunData.isRun =false;
            RunData.treeData = null;
        }

        return obj;
    };

};

 

//监听来自其他js的消息并作出响应
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    /**只对方法进行处理:而且参数为obj*/
    let method = Main[request.method];
    let param = request.param;
    if(typeof method === 'function') {
        let ret = method(param);
        //回调方法
        if(typeof sendResponse == 'function') {
            sendResponse(ret);
        }
    }
});